﻿using Simple.Contracts.Models.Common.Page;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Simple.Contracts.Models.Common
{
    public class Result<T>
    {
        /// <summary>
        /// code
        /// </summary>
        public int code { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string msg { get; set; }
        
        /// <summary>
        /// 结果
        /// </summary>
        public T? data { get; set; }

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Result<T> Success(T data)
        {
            return new Result<T>
            {
                code = (int)ResultCode.Success,
                msg = "成功",
                data = data
            };
        }

        /// <summary>
        /// 返回成功（针对分页）
        /// </summary>
        /// <param name="list"></param>
        /// <param name="total"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public static Result<PageDto<T>> PageSuccess(List<T> list, long total, PageInput input)
        {

            return new Result<PageDto<T>>
            {
                code = (int)ResultCode.Success,
                msg = "成功",
                data = new PageDto<T>
                {
                    list = list,
                    pageNum = input.pageNum,
                    pageSize = input.pageSize,
                    total = total
                }
            };
        }

        /// <summary>
        /// 友好提示
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result<T> FriendlyReminder(string message)
        {
            return new Result<T>
            {
                code = (int)ResultCode.FriendlyReminder,
                msg = message
            };
        }
    }

    /// <summary>
    /// 状态
    /// </summary>
    public enum ResultCode
    {
        /// <summary>
        /// 成功
        /// </summary>
        Success = 200,
        /// <summary>
        /// 友好提示
        /// </summary>
        FriendlyReminder = 500,
    }
}